<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let ary = [1, 2, 3, 1, 2, 1, 2, 3, 2, 1, 2, 3]
        //每一次拿出来的值都和后面的值进行比较，比较过程遇到相同的，把这一项删除splice
        for (var i = 0; i < ary.length; i++) {
            var item = ary[i]
            for (var j = i + 1; j < ary.length; j++) {
                var nextItem = ary[j]
                if (item == nextItem) {
                    ary.splice(j, 1)//有数组塌陷问题
                    j--//数组塌陷后，j后面的每一项索引都提前了一位，下一次要比较该是j这个索引的内容
                }
            }
        }
        console.log(ary);
    </script>
</body>

</html>